﻿/*************************************
 * Creator:SW-PeiYang
 * DateTime:2025/8/27 14:22:17
 * Description:<Description>
 * CopyRight:中广核研究院有限公司
 * ***********************************/

using System.Windows;

namespace SunnyPaine.Autofac.Extension.Mvvm.UI
{
    /// <summary>
    /// 用于显示消息框。
    /// </summary>
    public class MessageBoxService : BaseService, IMessageBoxService
    {
        #region 私有方法
        private static SPMessageBoxResult ToSPMessageBoxResult(MessageBoxResult result)
        {
            SPMessageBoxResult spResult = SPMessageBoxResult.None;
            switch (result)
            {
                case MessageBoxResult.None:
                    spResult = SPMessageBoxResult.None;
                    break;
                case MessageBoxResult.OK:
                    spResult = SPMessageBoxResult.OK;
                    break;
                case MessageBoxResult.Cancel:
                    spResult = SPMessageBoxResult.Cancel;
                    break;
                case MessageBoxResult.Yes:
                    spResult = SPMessageBoxResult.Yes;
                    break;
                case MessageBoxResult.No:
                    spResult = SPMessageBoxResult.No;
                    break;
                default:
                    break;
            }
            return spResult;
        }

        private static MessageBoxButton ToMessageBoxButton(SPMessageBoxButton spButton)
        {
            MessageBoxButton button = MessageBoxButton.OK;
            switch (spButton)
            {
                case SPMessageBoxButton.OK:
                    button = MessageBoxButton.OK;
                    break;
                case SPMessageBoxButton.OKCancel:
                    button = MessageBoxButton.OKCancel;
                    break;
                case SPMessageBoxButton.YesNoCancel:
                    button = MessageBoxButton.YesNoCancel;
                    break;
                case SPMessageBoxButton.YesNo:
                    button = MessageBoxButton.YesNo;
                    break;
                default:
                    break;
            }
            return button;
        }
        #endregion


        #region 公共方法，IMessageBoxService成员
        /// <summary>
        /// 显示一个消息框，具有一条自定义消息，并返回消息框按钮结果。
        /// </summary>
        /// <param name="messageBoxText">消息。</param>
        /// <returns></returns>
        public SPMessageBoxResult Show(string messageBoxText)
        {
            MessageBoxResult result = MessageBox.Show(messageBoxText);
            return ToSPMessageBoxResult(result);
        }

        /// <summary>
        /// 显示一个消息框，具有一条自定义消息和自定义标题栏标题，并返回消息框按钮结果。
        /// </summary>
        /// <param name="messageBoxText">消息。</param>
        /// <param name="caption">标题。</param>
        /// <returns></returns>
        public SPMessageBoxResult Show(string messageBoxText, string caption)
        {
            MessageBoxResult result = MessageBox.Show(messageBoxText, caption);
            return ToSPMessageBoxResult(result);
        }

        /// <summary>
        /// 显示一个消息框，具有一条自定义消息、自定义标题栏标题和自选消息框按钮，并返回消息框按钮结果。
        /// </summary>
        /// <param name="messageBoxText"></param>
        /// <param name="caption"></param>
        /// <param name="button"></param>
        /// <returns></returns>
        public SPMessageBoxResult Show(string messageBoxText, string caption, SPMessageBoxButton button)
        {
            MessageBoxResult result = MessageBox.Show(messageBoxText, caption, ToMessageBoxButton(button));
            return ToSPMessageBoxResult(result);
        }
        #endregion
    }
}
